#include <iostream>
#include <unistd.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();

    if (pid < 0) {
        std::cerr << "fork failed" << std::endl;
        return 1;
    } else if (pid == 0) {
        std::cout << "child: " << getpid() << std::endl;
        sleep(1);
    } else {
        std::cout << "parent: " << pid << std::endl;
        int status;
        waitpid(pid, &status, 0);
        std::cout << "child proc exited with: " << status << std::endl;
    }
    return 0;
}